package com.example.service;

import com.example.ui.ShopDetailActivity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.provider.MediaStore;

public class PictureUtil {
	public static void lookUp(Context context, String filePath) {
		if (filePath == null || filePath.isEmpty()) {
			return;
		}
		
		Intent intent = new Intent();
		intent.setAction(android.content.Intent.ACTION_VIEW);
		intent.setDataAndType(Uri.parse("file://"+filePath), "image/*");
		context.startActivity(intent);
	}
	
	public static Bitmap thumbnail(String filePath, int width, int height) {
		if (filePath == null || filePath.isEmpty()) {
			return null;
		}
		
		Bitmap bmp = BitmapFactory.decodeFile(filePath);
		if (bmp == null) {
			return null;
		}
		
		Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bmp, width, height);
		if (!bmp.isRecycled()) {
			bmp.recycle();
			bmp = null;
		}
		
		return thumbnail;
	}	
}
